<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购订单审核列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>采购订单编号：</label>
                                <input type="text" name="orderCode"/>
                            </li>
                            <li>
                                <label>供应商名称：</label>
                                <input type="text" name="supplierName"/>
                            </li>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="productName"/>
                            </li>
                            <li>
                                <label>采购日期：</label>
                                <input type="text" class="time-input" placeholder="请选择采购日期" name="orderDate"/>
                            </li>
                            <li>
                                <label>审核状态：</label>
                                <select name="auditStatus" th:with="type=${@dict.getType('proc_audit_status')}">
                                    <option value="">所有</option>
                                    <option value="0">未审核</option>
                                    <option value="1">审核通过</option>
                                    <option value="2">审核不通过</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group" shiro:hasPermission="purchase:audit:approve">
                <a class="btn btn-success multiple disabled" onclick="batchApprove()">
                    <i class="fa fa-check"></i> 批量审核通过
                </a>
                <a class="btn btn-danger multiple disabled" onclick="batchReject()">
                    <i class="fa fa-ban"></i> 批量审核不通过
                </a>
            </div>
            
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var detailFlag = [[${@permission.hasPermi('purchase:audit:view')}]];
        var auditFlag = [[${@permission.hasPermi('purchase:audit:view')}]];
        var approveFlag = [[${@permission.hasPermi('purchase:audit:approve')}]];
        var rejectFlag = [[${@permission.hasPermi('purchase:audit:reject')}]];
        var statusDatas = [[${@dict.getType('proc_order_status')}]];
        var auditStatusDatas = [[${@dict.getType('proc_audit_status')}]];
        var categoryDatas = [[${@dict.getType('product_category')}]];
        var prefix = ctx + "purchase/audit";

        $(function() {
            var options = {
                url: prefix + "/list",
                sortName: "createdTime",
                sortOrder: "desc",
                modalName: "采购订单审核",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'orderId',
                    title: '采购订单ID',
                    visible: false
                },
                {
                    field: 'orderCode',
                    title: '采购订单编号'
                },
                {
                    field: 'supplierId',
                    title: '供应商ID',
                    visible: false
                },
                {
                    field: 'supplierName',
                    title: '供应商名称'
                },
                {
                    field: 'productName',
                    title: '商品名称'
                },
                {
                    field: 'categoryId',
                    title: '商品类别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(categoryDatas, value);
                    }
                },
                {
                    field: 'orderDate',
                    title: '采购日期'
                },
                {
                    field: 'expectedDate',
                    title: '预计到货日期'
                },
                {
                    field: 'totalAmount',
                    title: '订单总金额'
                },
                {
                    field: 'status',
                    title: '订单状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(auditStatusDatas, value);
                    }
                },
                {
                    field: 'createdBy',
                    title: '创建者'
                },
                {
                    field: 'createdTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.orderId + '\')"><i class="fa fa-search"></i>详情</a> ');
                        
                        // 所有订单都显示审核按钮，允许重新审核
                        actions.push('<a class="btn btn-primary btn-xs ' + auditFlag + '" href="javascript:void(0)" onclick="toAudit(\'' + row.orderId + '\')"><i class="fa fa-check-circle"></i>审核</a>');
                        
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        /* 查看订单详情 */
        function detail(orderId) {
            var url = prefix + '/detail/' + orderId;
            $.modal.open("查看采购订单", url);
        }
        
        /* 跳转到订单审核页面 */
        function toAudit(orderId) {
            var url = prefix + '/toAudit/' + orderId;
            $.modal.open("审核采购订单", url);
        }
        
        /* 批量审核通过 */
        function batchApprove() {
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要批量审核通过选中的" + rows.length + "条数据吗?", function() {
                var url = prefix + "/batchApprove";
                var data = { "ids": rows.join(), "auditOpinion": "批量审核通过" };
                $.operate.submit(url, "post", "json", data);
            });
        }
        
        /* 批量审核不通过 */
        function batchReject() {
            var rows = $.table.selectFirstColumns();
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.confirm("确认要批量审核不通过选中的" + rows.length + "条数据吗?", function() {
                var url = prefix + "/batchReject";
                var data = { "ids": rows.join(), "auditOpinion": "批量审核不通过" };
                $.operate.submit(url, "post", "json", data);
            });
        }
    </script>
</body>
</html> 